//
//  HomeSmallView.swift
//  VastSwift
//
//  Created by BestVast on 2021/5/28.
//

import UIKit

// 点击view的回调
typealias ClickViewSure = () -> ()

// 最小的单元格,宽70，高90
class HomeSmallView: UIView {
    
    // 展示的图片
    var showImageView: UIImageView!
    // 底部标题
    var titleLabel: UILabel!
    // 右上角显示数字。默认不显示
    var numLabel: UILabel!
    // 点击view回调事件
    private var tap: ClickViewSure?
    
    func showViewInfo(text: String, textColor: UIColor = .gray, numHide: Bool = true, num: Int = 0, handle CompletionHandle: @escaping ClickViewSure) {
        titleLabel.text = text
        titleLabel.textColor = textColor
        if numHide == false {
            
            numLabel.isHidden = numHide
            numLabel.text = "\(num)"
        }
        tap = CompletionHandle
    }
    @objc func clickView() {
        if let click = tap {
            click()
        }
    }
    
    func uiConfig() -> Void {
        self.backgroundColor = .clear
        let height1 = self.frame.size.height
        let width1 = self.frame.size.width
        showImageView = UIImageView.init(frame: CGRect.init(x: (width1 - 50) / 2, y: 10, width: 50, height: 50))
        showImageView.backgroundColor = .cyan
        showImageView.isUserInteractionEnabled = true
        titleLabel = UILabel.init(frame: CGRect.init(x: 0, y: showImageView.bottom + 10, width: width1, height: 20))
        titleLabel.textAlignment = .center
        titleLabel.textColor = .gray
        titleLabel.font = .systemFont(ofSize: 14)
        self.addSubview(showImageView)
        self.addSubview(titleLabel)
        
        let tap = UITapGestureRecognizer.init(target: self, action: #selector(clickView))
        self.addGestureRecognizer(tap)
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.uiConfig()
    }
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
}
